# Maintainer: Caleb Connolly <caleb@postmarketos.org>
# Co-Maintainer: Clayton Craft <clayton@craftyguy.net>
pkgname=postmarketos-initramfs
pkgver=3.7.0
pkgrel=0
pkgdesc="Base files for the postmarketOS initramfs / initramfs-extra"
url="https://postmarketos.org"
options="!check"  # no tests
provides="postmarketos-ramdisk=$pkgver-r$pkgrel"
provider_priority=10
depends="
	blkid
	btrfs-progs
	buffyboard
	busybox-extras
	bzip2
	cryptsetup
	device-mapper
	devicepkg-utils>=0.2.0
	dosfstools
	e2fsprogs
	e2fsprogs-extra
	f2fs-tools
	font-terminus
	iskey
	kmod
	libinput-libs
	lz4
	multipath-tools
	parted
	postmarketos-fde-unlocker
	postmarketos-mkinitfs>=2.2
	udev
	unudhcpd
	util-linux-misc
	xz
	"
makedepends="
	postmarketos-base-nofde
"
source="
	00-default.modules
	00-initramfs-base.dirs
	00-initramfs-base.files
	00-initramfs-extra-base.files
	init.sh
	init_functions.sh
	init_2nd.sh
	init_functions_2nd.sh
	mdev.conf
	unudhcpd.conf
	"
arch="noarch"
license="GPL-2.0-or-later"

build() {
	mkdir -p "$builddir"

	# Replace <<INITRAMFS_PKG_VERSION>> with the actual version
	sed "s|<<INITRAMFS_PKG_VERSION>>|$pkgver-r$pkgrel|" \
		"$srcdir/init.sh" > "$builddir/init.sh"
}

package() {
	install -Dm644 "$srcdir/unudhcpd.conf" \
		"$pkgdir/etc/unudhcpd.conf"

	install -Dm644 "$srcdir"/mdev.conf \
		-t "$pkgdir"/usr/share/initramfs/


	install -Dm644 "$srcdir/init_functions.sh" \
		"$pkgdir/usr/share/initramfs/init_functions.sh"

	install -Dm644 "$srcdir/init_functions_2nd.sh" \
		"$pkgdir/usr/share/initramfs/init_functions_2nd.sh"

	install -Dm755 "$builddir/init.sh" \
		"$pkgdir/usr/share/initramfs/init.sh"

	install -Dm755 "$srcdir/init_2nd.sh" \
		"$pkgdir/usr/share/initramfs/init_2nd.sh"

	install -Dm644 "$srcdir"/00-initramfs-base.dirs \
		-t "$pkgdir"/usr/share/mkinitfs/dirs/
	mkdir -p "$pkgdir"/etc/mkinitfs/dirs

	install -Dm644 "$srcdir"/00-default.modules \
		-t "$pkgdir"/usr/share/mkinitfs/modules/
	mkdir -p "$pkgdir"/etc/mkinitfs/modules

	install -Dm644 "$srcdir"/00-initramfs-base.files \
		-t "$pkgdir"/usr/share/mkinitfs/files/
	mkdir -p "$pkgdir"/etc/mkinitfs/files

	install -Dm644 "$srcdir"/00-initramfs-extra-base.files \
		-t "$pkgdir"/usr/share/mkinitfs/files-extra/
	mkdir -p "$pkgdir"/etc/mkinitfs/files-extra

	mkdir -p "$pkgdir"/usr/share/mkinitfs/hooks
	mkdir -p "$pkgdir"/usr/share/mkinitfs/hooks-extra
	mkdir -p "$pkgdir"/etc/mkinitfs/hooks
	mkdir -p "$pkgdir"/etc/mkinitfs/hooks-extra
}

sha512sums="
911ff425021fb59061cae182ddab3c6fd6e93fb126e2e45ccdb74f73b3d65b0f454f86a533364dc7cdc94f79538aec53a168f2d83c38218dc82a19cb0bf9b244  00-default.modules
9c0e8f6f61d5da191e03a1aa9d5d0ceb5baf1eae6dbb9bfb0af59817783525119ac8394b135f303f7b6434a3eab0b49185fb90379e06823db847a4999c75ce33  00-initramfs-base.dirs
c0233d22858a5901db64e1d2fe1f6d39a2e2cfd1b94a10932483f55fed9461e9b8aa2d73b154b9d99a7a8b49ee02abfbddfe917ce0c6d7576601ba2668589c01  00-initramfs-base.files
d0f35562365756d93066ce45924d17fb347b54095179c3262daa2f073e12743505cd5d9372ad30485915ca754d95a8edba9a74314e7949e0b3cf6978a87d03a5  00-initramfs-extra-base.files
c497ace6f3d183c48722b9e4fd2b6fed21338d68a9e729c1423d3c3de3eaae7366d8dd75a11f78b7072a6795dcc5380c10d8b390738372ede6dc78074ae87a76  init.sh
3a0010dbec4f349f7da64d2cf87b0e1665009bf0361fe4d50b10f1f92caf98f35d077159d7d3577ddb730dc60a7bfbb67fb50fc5f4bc27882d59679e7dc865f0  init_functions.sh
2d531177a7310ab95910379b3ab816ab8ba75520e1c11adf295f5ff8247d74553fe3a325c56c66aba4e41e33f0e813b0360c45b847983c1df448d5fb176e02cb  init_2nd.sh
5ed5d96c45db0b32b6ff5f5e63b2821e442baf57c3ba587555e2cd92986c65aa13bc73ae591a8b35845e5d30384daf13b76e83961bd7cfe674a81320b34748d9  init_functions_2nd.sh
675e7d5bee39b2df7d322117f8dcaccc274d61beaf4d50ead19bbf2109446d64b1c0aa0c5b4f9846eb6c1c403418f28f6364eff4537ba41120fbfcbc484b7da7  mdev.conf
ba3275a9af788c7c782322a22a0f144d5e50e3498ea6886486a29331f23ae89cd32d500a3635cfa7cab369afba92edc18aeca64ccbf0cd589061cce23d15b46c  unudhcpd.conf
"
